package com.zhongyu.controller;


import com.zhongyu.pojo.Panyingpankui;
import com.zhongyu.pojo.StoreDetail;
import com.zhongyu.pojo.User;
import com.zhongyu.service.PKYKService;
import com.zhongyu.service.StoreDetailService;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.PkykVo;
import com.zhongyu.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/kucun/pkyk/")
public class PKYKController {

    @Resource
    private PKYKService pkykService;

    @Resource
    private StoreDetailService storeDetailService;

    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize , PkykVo pkykVo){
        PageResult pageResult=pkykService.searchAll(pageNo, pageSize,pkykVo);
        return ResultVo.success(pageResult);
    }

    @PostMapping("/add")
    public ResultVo add(@RequestBody Panyingpankui panyingpankui, HttpSession session) {
        try {
            System.out.println("盘盈盘亏"+panyingpankui);
            pkykService.add(panyingpankui,session);
            return ResultVo.success("盘盈盘亏登记成功!");
        } catch (Exception ex) {
            return ResultVo.failure("盘盈盘亏登记失败!", ex);
        }
    }
    @GetMapping("/searchAll/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize){
        PageResult pageResult=pkykService.searchAll(pageNo, pageSize);
        return ResultVo.success(pageResult);
    }

    @GetMapping("/list")
    public ResultVo list1(Integer id){
        Panyingpankui list=pkykService.searchAll(id);
        return ResultVo.success(list);
    }
 /*   @GetMapping("/update")//post请求要加@RequestBody进行接收
    public ResultVo update(@RequestBody Integer state,LocalDateTime checktime, Integer id, Integer shenhe,HttpSession session) {
        try {
            pkykService.update(state,checktime,shenhe,id,session);
            return ResultVo.success("审核成功");
        } catch (Exception ex) {
            return ResultVo.failure("审核失败", ex);
        }

    }*/
 @PostMapping("/update")//post请求要加@RequestBody进行接收
 public ResultVo update(@RequestBody StoreDetail storeDetail, HttpSession session) {
     try {
         System.out.println(storeDetail);
         storeDetailService.updatePyPk(storeDetail,session);
        /* LocalDateTime localDateTime=panyingpankui.setChecktime(LocalDateTime.now());
         Integer state= panyingpankui.setState(Panyingpankui.STATE_CHECK);
         User loginUser= (User) session.getAttribute("loginUser");
         Integer shenhe=loginUser.getId();
         Integer id=panyingpankui.getId();
         pkykService.update(state,localDateTime,id,shenhe,session,panyingpankui);*/
         return ResultVo.success("盘盈盘亏审核成功");
     } catch (Exception ex) {
         return ResultVo.failure("盘盈盘亏审核失败", ex);
     }

 }

}
